package com.vcredit.creditcat.service;

import com.vcredit.creditcat.redis.RedisServiceExt;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class BaseBusinessService {
	@Autowired
	private RedisServiceExt redisService;

	private final long cacheTime = 3600;

	protected void cache(String key, Object item) {
		Object object = redisService.get(key);
		if (object != null) {
			redisService.del(key);
		}
		redisService.put(key, item, cacheTime);
	}

	protected Object get(String key) {
		return redisService.get(key);
	}

	protected void del(String key) {
		Object object = redisService.get(key);
		if (object != null) {
			redisService.del(key);
		}
	}
}
